package utils;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/******************************************
 * Filename			: UtilsOnScopes.java
 * Decription		: Các utility trên session, application,...
 * Created date		: Jun 2, 2008
 * Author			: Phonglt
 ******************************************/
public class UtilsOnScopes {
 
	/**************************************
	 * Method name		: getSession
	 * Return type		: HttpSession
	 * Description		: tao ra session
	 * Created date		: Jun 2, 2008
	 * Author			: Honglk
	 **************************************/
	public static HttpSession getSession() {
		FacesContext context = FacesContext.getCurrentInstance();
		HttpSession session = (HttpSession) context.getExternalContext()
				.getSession(false);
		return session;
	}
	
	/**************************************
	 * Method name		: getRequset
	 * Return type		: HttpServletRequest
	 * Decription		:Tao request
	 * Created date		: Jun 6, 2008
	 * Author			: Honglk
	 **************************************/
	public static HttpServletRequest getRequest() {
		FacesContext context = FacesContext.getCurrentInstance();
		HttpServletRequest request = (HttpServletRequest) context
				.getExternalContext().getRequest();
		return request;
	}
	/**************************************
	 * Method name		: getResponse
	 * Return type		: HttpServletResponse
	 * Decription		:Tao respone
	 * Created date		: Jun 15, 2008
	 * Author			: Honglk
	 **************************************/
	public static HttpServletResponse getResponse() {
		FacesContext context = FacesContext.getCurrentInstance();
		HttpServletResponse response = (HttpServletResponse) context
		.getExternalContext().getResponse();
		return response;
	}
	
	/**************************************
	 * Method name		: getUserName
	 * Return type		: String
	 * Decription		:Lay ra userName da dang nhap
	 * Created date		: Jun 14, 2008
	 * Author			: Honglk
	 **************************************/
	public static String getUserName(){
		HttpSession session = UtilsOnScopes.getSession();
		quantri.login.User user = (quantri.login.User)session.getAttribute("user");
		String userName = user.userName;
		return userName;
	}


}
